import 'package:flutter/material.dart';

class NewRoute extends StatelessWidget {
  const NewRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("New route"),
      ),
      body: const Center(
        child: Text("This is new route"),
      ),
    );
  }
}

/// 路由跳转带参数，比如打开商品详情页时，我们需要带一个商品id，这样商品详情页才知道展示哪个商品信息；
/// 又比如我们在填写订单时需要选择收货地址，打开地址选择页并选择地址后，可以将用户选择的地址返回到订单页
///
///  */

// ignore: must_be_immutable
class TipRoute extends StatelessWidget {
  TipRoute({Key? key, required this.title}) : super(key: key);
  String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('提示'),
      ),
      body: Center(
        child: Column(
          children: [
            Text(title),
            ElevatedButton(
              onPressed: () => Navigator.pop(context, '这里是返回值'),
              child: const Text('点击返回'),
            )
          ],
        ),
      ),
    );
  }
}

class RouterTestRoute extends StatelessWidget {
  const RouterTestRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('跳转1'),
      ),
      body: Center(
        child: Column(
          children: [
            const Text('跳转到下一个页面'),
            ElevatedButton(
              onPressed: () async {
                var reslut = await Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return TipRoute(title: "提示******");
                }));
                print("返回值: $reslut");
              },
              child: const Text('点击跳转'),
            )
          ],
        ),
      ),
    );
  }
}
